package com.zxy.ziems.server.alarm.controller;

import com.zxy.btp.common.response.PageResult;
import com.zxy.ziems.server.alarm.enums.AlarmModeEnum;
import com.zxy.ziems.server.alarm.pojo.dto.AlarmRuleAddDTO;
import com.zxy.ziems.server.alarm.pojo.param.AlarmTypePageParam;
import com.zxy.ziems.server.alarm.pojo.vo.AlarmRuleVO;
import com.zxy.ziems.server.alarm.service.AlarmRuleService;
import com.zxy.ziems.server.vo.OptionsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 告警管理-告警通知管理
 *
 * @Copyright (C),
 * @ClassName: AlarmRuleController
 * @Author: yanzhiwei
 * @Description: 告警规则
 * @Date: 2024/4/10 13:26
 */
@RestController
@Validated
@RequestMapping("/api/alarm/rule")
public class AlarmRuleController {


    /**
     * 新增告警通知规则
     *
     * @param alarmRuleAddDTO
     */
    @PostMapping("/add")
    public void saveAlarmRuleEntity(@Validated(value = AlarmRuleAddDTO.Add.class) @RequestBody AlarmRuleAddDTO alarmRuleAddDTO) {
        service.saveAlarmRuleEntity(alarmRuleAddDTO);
    }

    /**
     * 更新告警通知规则
     *
     * @param alarmRuleAddDTO
     */
    @PostMapping("/update")
    public void update(@RequestBody AlarmRuleAddDTO alarmRuleAddDTO) {
        service.saveAlarmRuleEntity(alarmRuleAddDTO);
    }

    /**
     * 启用，停用
     *
     * @param alarmRuleAddDTO
     */
    @PostMapping("/updateStatus")
    public void updateStatus(@RequestBody AlarmRuleAddDTO alarmRuleAddDTO) {
        service.saveAlarmRuleEntity(alarmRuleAddDTO.getId(), alarmRuleAddDTO.getStatus());
    }

    /**
     * 删除告警规则
     *
     * @param alarmRuleAddDTO
     * @return
     */
    @PostMapping("/delete")
    public boolean delete(@RequestBody AlarmRuleAddDTO alarmRuleAddDTO) {
        return service.deleteById(alarmRuleAddDTO.getId());
    }


    /**
     * 分页查询告警类型
     *
     * @return
     */
    @GetMapping("/page")
    public PageResult<AlarmRuleVO> page(@Validated AlarmTypePageParam param) throws Exception {
        return service.pageListBy(param);
    }

    /**
     * 告警通知方式
     *
     * @return
     */
    @GetMapping("/alarmMode")
    public List<OptionsVO> alarmModelList() {
        return AlarmModeEnum.mapTolist();
    }


    private AlarmRuleService service;

    @Autowired
    public void setService(AlarmRuleService alarmRuleService) {
        this.service = alarmRuleService;
    }

}
